<template>
	<el-dialog title="发送手机短信" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="接收人" prop="accountIds">
				<select-user-dialog v-model:accountId="form.accountIds" :mode="true"/>
			</el-form-item>
			<el-form-item label="外部人员" prop="outUser">
				<el-input type="textarea" v-model="form.outUser" placeholder="手机号码以','间隔" rows="2"></el-input>
			</el-form-item>
			<el-form-item label="发送时间" prop="sendTime">
				<el-date-picker
					style="width: 100%"
					:disabled-date="publishDateAfter"
					v-model="form.sendTime"
					type="datetime"
					value-format="YYYY-MM-DD HH:mm:ss"
					placeholder="选择时间">
				</el-date-picker>
			</el-form-item>
			<el-form-item label="消息内容" prop="content">
				<el-input type="textarea" v-model="form.content" placeholder="消息内容" rows="4"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">发 送</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog
	},
	data() {
		return {
			dialog: {
				isShow: false
			},
			visible: false,
			isSaveing: false,
			isShowMsg: false,
			form: {
				accountIds: '',
				outUser:'',
				sendTime:'',
				content:''
			},
			rules: {
				content:[
					{required: true, message: '消息内容不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		publishDateAfter(time){
			return time.getTime()<=Date.now();
		},
		//显示
		open() {
			this.visible = true;
			return this
		},
		submit() {
			if(this.form.accountIds=="@all")
			{
				this.$alert("您不能全局发送站内信！", "提示", {type: 'error'});
				return;
			}
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {

					this.isSaveing = true;
					var res = await this.$API.system.mobilesms.sendMobileSms.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$emit('success')
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
	}
}
</script>

<style>
</style>
